package com.jxdinfo.hussar.cloud.module.example.lift.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxdinfo.hussar.cloud.module.example.lift.dao.LiftNoticeDao;
import com.jxdinfo.hussar.cloud.module.example.lift.dto.LiftNoticeSearchDto;
import com.jxdinfo.hussar.cloud.module.example.lift.model.Lift;
import com.jxdinfo.hussar.cloud.module.example.lift.model.LiftHistoryCount;
import com.jxdinfo.hussar.cloud.module.example.lift.model.LiftNotice;
import com.jxdinfo.hussar.cloud.module.example.lift.service.LiftNoticeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 升降机异常通知(LiftNotice)表服务实现类
 *
 * @author makejava
 * @since 2023-10-23 18:28:35
 */
@Service("liftNoticeService")
public class LiftNoticeServiceImpl extends ServiceImpl<LiftNoticeDao, LiftNotice> implements LiftNoticeService {
    @Resource
    private LiftNoticeDao liftNoticeDao;
    @Override
    public Page<LiftNotice> findPage(LiftNoticeSearchDto dto) {

        LambdaQueryWrapper<LiftNotice> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(ObjectUtils.isNotEmpty(dto.getTyProjectCode()),LiftNotice::getTyProjectCode,dto.getTyProjectCode())
                .eq(LiftNotice::getNoticeStatus,1)
                .eq(ObjectUtils.isNotEmpty(dto.getLiftId()),LiftNotice::getLiftId,dto.getLiftId())
                .eq(ObjectUtils.isNotEmpty(dto.getNoticeLevel()),LiftNotice::getNoticeLevel,dto.getNoticeLevel())
                .eq(ObjectUtils.isNotEmpty(dto.getNoticeType()),LiftNotice::getNoticeType,dto.getNoticeType())
                .ge(ObjectUtils.isNotEmpty(dto.getTyCreateTimeStart()),LiftNotice::getSendTime,dto.getTyCreateTimeStart())
                .le(ObjectUtils.isNotEmpty(dto.getTyCreateTimeEnd()),LiftNotice::getSendTime,dto.getTyCreateTimeEnd())
                .orderByDesc(LiftNotice::getSendTime)
                .orderByAsc(LiftNotice::getReadStatus);
        Page<LiftNotice> page = new Page(dto.getPage(),dto.getRows());
        Page<LiftNotice> mapsPage = liftNoticeDao.selectPage(page, queryWrapper);
        return mapsPage;
    }
}

